package com.ruicar.afs.cloud.common.vo;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.ruicar.afs.cloud.common.modules.contract.enums.LendingDirection;
import com.ruicar.afs.cloud.common.modules.contract.enums.VoucherSendStatus;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.Date;

/**
 * @author infinity
 * @version 1.0
 * @date 2020/8/19 11:40
 */
@Data
public class AccountVoucherInfoVo {
    private static final long serialVersionUID = 1L;
    @ApiModelProperty("唯一标识")
    @JsonSerialize(
            using = ToStringSerializer.class
    )
    @JSONField(
            serializeUsing = com.alibaba.fastjson.serializer.ToStringSerializer.class
    )
    @TableId(
            value = "id",
            type = IdType.ASSIGN_ID
    )
    private Long id;
    @ApiModelProperty("凭证流水号")
    @NotBlank(message = "凭证流水号不能为空")
    private String voucherSerialNumber ;
    @ApiModelProperty("总金额")
    private BigDecimal totalAmount;
    @ApiModelProperty("主业务事件")
    @NotBlank(message = "主业务事件不能为空")
    private String mainBusiness;

    @ApiModelProperty("主事件代码")
    @NotBlank(message = "主事件代码不能为空")
    private String mainBusinessCode;

    @ApiModelProperty("子业务事件")
    @NotBlank(message = "子业务事件不能为空")
    private String childBusiness;

    @ApiModelProperty("子事件代码")
    @NotBlank(message = "子事件代码不能为空")
    private String childBusinessCode;
    @ApiModelProperty("凭证号")
    @NotBlank(message = "凭证号不能为空")
    private String voucherNo ;
    @ApiModelProperty("分录号")
    private String entryNo ;

    @ApiModelProperty("合同号")
    private String contractNo ;
    @ApiModelProperty("科目")
    private String subjectCode ;

    @ApiModelProperty("供应商名称")
    @NotBlank(message = "供应商名称不能为空")
    private String dealerName ;

    @ApiModelProperty("业务交易流水号")
    private String businessNo ;

    @ApiModelProperty("会计年度")
    private String fiscalYear ;

    @ApiModelProperty("会计期间")
    private String accountingPeriod ;

    @ApiModelProperty("制单日期")
    private Date preparedDate ;

    @ApiModelProperty("记账日期")
    private Date postingDate ;

    @ApiModelProperty("借贷方向")
    @NotNull(message = "借贷方向不能为空")
    private LendingDirection lendingDirection ;

    @ApiModelProperty("借方金额")
    @NotBlank(message = "借方金额不能为空")
    private BigDecimal debitAmt ;

    @ApiModelProperty("贷方金额")
    @NotBlank(message = "贷方金额不能为空")
    private BigDecimal creditAmt ;

    @ApiModelProperty("摘要")
    @NotBlank(message = "摘要不能为空")
    private String explanation ;

    @ApiModelProperty("交易状态 枚举值：待发送，成功，失败")
    @NotNull(message = "交易状态不能为空")
    private VoucherSendStatus status;

    @ApiModelProperty("来源系统")
    private String sourceSystem;

    @ApiModelProperty("案件类型")
    private String caseType;

    @ApiModelProperty("错误信息")
    private String errMsg ;

    public static AccountVoucherInfoVo convertFrom(VoucherInfoVo voucherInfo){
        AccountVoucherInfoVo info = new AccountVoucherInfoVo();
        info.setMainBusiness(voucherInfo.getMainBusiness());
        info.setMainBusinessCode(voucherInfo.getMainBusinessCode());
        info.setChildBusiness(voucherInfo.getChildBusiness());
        info.setChildBusinessCode(voucherInfo.getChildBusinessCode());
        info.setExplanation(voucherInfo.getChildBusiness());
        return info;
    }
}
